import request from '@/utils/request'
import axios from 'axios'

const key = '87afd5c9969f4ba7a396182d60ceb440'

// 天气生活指数
function indices(location, type) {
  return axios.request({
    url: `https://devapi.qweather.com/v7/indices/1d?key=${key}&location=${location}&type=${type}`
  })
}

// 紫外线指数
export function getDailyUV(location, type) {
  return indices(location, type)
}

// 实时天气
export function gridWeather(location) {
  return axios
    .request({
      url: `https://devapi.qweather.com/v7/weather/now?key=${key}&location=${location}`
    })
    .then(r => {
      r.data.now.temp = 35
      return r
    })
}

// 7天
export function next7d(location) {
  return axios.request({
    url: `https://devapi.qweather.com/v7/weather/7d?key=${key}&location=${location}`
  })
}

// 预警
export function waring(location) {
  return axios.request({
    url: `https://devapi.qweather.com/v7/warning/now?key=${key}&location=${location}`
  })
}

// 久富气象站
export function getWeather(farm_id) {
  return request({
    url: `/api/v2/base/farm/farmSq/getQxzDataForLSD${farm_id ? `?farm_id=${farm_id}` : ''}`
  }).then(({ data }) => data)
}
